package com.iplay.dahua.chapter2.strategy;

import com.iplay.dahua.chapter2.simpleFactory.BaseCashSuper;
import com.iplay.dahua.chapter2.simpleFactory.CashNormal;
import com.iplay.dahua.chapter2.simpleFactory.CashRebate;
import com.iplay.dahua.chapter2.simpleFactory.CashReturn;

/**
 * @author dangwu
 * @since 2021/7/21 3:47 下午
 */
public class CashContext {
    private BaseCashSuper bcs;

    /**
     * 策略与简单工厂结合
     * @param type
     */
    public CashContext(String type) {
        switch (type){
            case "1":
                bcs = new CashNormal();
                break;
            case "2":
                bcs = new CashRebate(0.8);
                break;
            case "3":
                bcs = new CashReturn(300, 100);
                break;
            default:
                break;
        }
    }

    public double calMoney(double money) {
        return bcs.acceptCash(money);

    }
}
